package com.jin.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.zip.CheckedOutputStream;

public class OrderConfirmVo {
    //收货地址
    @Setter @Getter
    List<MemberAddressVo> address;
    //所有选中的购物项
    @Setter @Getter
    List<OrderItemVo> items;
    //发票记录
    //优惠券信息(积分)

    //库存信息
    @Setter @Getter
    Map<Long, Boolean> hasStocks;

    //要购买的商品的数量
    public Integer getCount() {
        Integer count=0;
        if(items!=null){
            for (OrderItemVo item : items) {
                count = count + item.getCount();
            }
        }
        return count;
    }

    @Setter @Getter
    Integer integration;

    //防重令牌
    @Setter @Getter
    String orderToken;

    //订单总额
    //BigDecimal total;
    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if(items!=null){
            for (OrderItemVo item : items) {
                total=total.add(item.getPrice().multiply(new BigDecimal(item.getCount().toString())));
            }
        }
        return total;
    }

    //应付价格
    //BigDecimal payPrice;
    public BigDecimal getPayPrice() {
        return getTotal();
    }
}
